# coding: utf-8
# author: dengpanxiao(@126.com)
# WSGI(Web Sever Gateway Interface)，使用python内置的WSCI服务器模块wsgiref，仅供测试使用

from wsgiref.simple_server import make_server

def application(environ, start_reponse):
    '''
    :param environ: 包含所有HTTP请求信息的dict对象
    :param start_reponse: 发送HTTP响应的函数
    :return: 
    '''
    start_reponse('200 OK', [('Content-Type', 'text/html')])
    return "<h1>Hello %s!</h1>" % (environ['PATH_INFO'][1:] or 'web')

if __name__ == "__main__":
    # 创造一个服务器，ip地址为空，端口号为8000，处理函数是application
    httpd = make_server('', 8000, application)
    print "Serving HTTP on port 8000..."
    # 开始监听HTTP请求
    httpd.serve_forever()
